<!DOCTYPE html>
<html lang=zh-CN>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta property="og:description" content="samuel-24276的博客">
    <meta property="og:type" content="website">
    <meta name="description" content="samuel-24276的博客">
    <meta name="keyword"  content="aircloud">
    <link rel="shortcut icon" href="/myblog/img/favicon.ico">

    <title>
        
        QT学习日记（4）——各类事件及事件分发器、过滤器 - samuel-24276的博客 | samuel-24276&#39;s Blog
        
    </title>

    <!-- Custom CSS -->
    
<link rel="stylesheet" href="/myblog/css/aircloud.css">

    
<link rel="stylesheet" href="/myblog/css/gitment.css">

    <!--<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">-->
    <link href="//at.alicdn.com/t/font_620856_28hi1hpxx24.css" rel="stylesheet" type="text/css">
    <!-- ga & ba script hoook -->
    <script></script>
<meta name="generator" content="Hexo 7.1.1"></head>

<body>

<div class="site-nav-toggle" id="site-nav-toggle">
    <button>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
        <span class="btn-bar"></span>
    </button>
</div>

<div class="index-about">
    <i> Like what you do, do what you like </i>
</div>

<div class="index-container">
    
    <div class="index-left">
        
<div class="nav" id="nav">
    <div class="avatar-name">
        <div class="avatar ">
            <img src="/myblog/img/avatar.jpg" />
        </div>
        <div class="name">
            <i>samuel-24276</i>
        </div>
    </div>
    <div class="contents" id="nav-content">
        <ul>
            <li >
                <a href="/myblog/">
                    <i class="iconfont icon-shouye1"></i>
                    <span>主页</span>
                </a>
            </li>
            <li >
                <a href="/myblog/tags">
                    <i class="iconfont icon-biaoqian1"></i>
                    <span>标签</span>
                </a>
            </li>
            <li >
                <a href="/myblog/archives">
                    <i class="iconfont icon-guidang2"></i>
                    <span>存档</span>
                </a>
            </li>
            <li >
                <a href="/myblog/collect/">
                    <i class="iconfont icon-shoucang1"></i>
                    <span>收藏</span>
                </a>
            </li>
            <li >
                <a href="/myblog/about/">
                    <i class="iconfont icon-guanyu2"></i>
                    <span>关于</span>
                </a>
            </li>
            
            <li>
                <a id="search">
                    <i class="iconfont icon-sousuo1"></i>
                    <span>搜索</span>
                </a>
            </li>
            
        </ul>
    </div>
    
        <div id="toc" class="toc-article">
    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#10-%E9%BC%A0%E6%A0%87%E4%BA%8B%E4%BB%B6"><span class="toc-text">10.鼠标事件</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#11-%E5%AE%9A%E6%97%B6%E5%99%A8%E4%BA%8B%E4%BB%B6"><span class="toc-text">11.定时器事件</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#12-%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E5%99%A8"><span class="toc-text">12.事件分发器</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#13-%E4%BA%8B%E4%BB%B6%E8%BF%87%E6%BB%A4%E5%99%A8"><span class="toc-text">13.事件过滤器</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#14-%E7%BB%98%E5%9B%BE%E4%BA%8B%E4%BB%B6"><span class="toc-text">14.绘图事件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#14-1-%E5%9F%BA%E6%9C%AC%E7%BB%98%E5%9B%BE%E4%BA%8B%E4%BB%B6"><span class="toc-text">14.1.基本绘图事件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14-2-%E9%AB%98%E7%BA%A7%E7%BB%98%E5%9B%BE%E4%BA%8B%E4%BB%B6"><span class="toc-text">14.2.高级绘图事件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#14-3-%E7%BB%98%E5%9B%BE%E8%AE%BE%E5%A4%87"><span class="toc-text">14.3.绘图设备</span></a></li></ol></li></ol>
</div>
    
</div>


<div class="search-field" id="search-field">
    <div class="search-bg" id="search-bg"></div>
    <div class="search-container">
        <div class="search-input">
            <span id="esc-search"> <i class="icon-fanhui iconfont"></i></span>
            <input id="search-input"/>
            <span id="begin-search">搜索</span>
        </div>
        <div class="search-result-container" id="search-result-container">

        </div>
    </div>
</div>

        <div class="index-about-mobile">
            <i> Like what you do, do what you like </i>
        </div>
    </div>
    
    <div class="index-middle">
        <!-- Main Content -->
        


<div class="post-container">
    <div class="post-title">
        QT学习日记（4）——各类事件及事件分发器、过滤器
    </div>

    <div class="post-meta">
        <span class="attr">发布于：<span>2019-10-14 17:15:38</span></span>
        
        <span class="attr">标签：/
        
        <a class="tag" href="/myblog/tags/#Qt" title="Qt">Qt</a>
        <span>/</span>
        
        
        </span>
        <span class="attr">访问：<span id="busuanzi_value_page_pv"></span>
</span>
</span>
    </div>
    <div class="post-content no-indent">
        <h1 id="10-鼠标事件"><a href="#10-鼠标事件" class="headerlink" title="10.鼠标事件"></a>10.鼠标事件</h1><p>新建项目QtEvent，向widget.ui拖入一个label控件，删除里面的文字，在右下角的QFrame中找到frameShape,修改为Box，使其在设计界面可见。<br>在项目名上右键-&gt;Add New-&gt;C++ Class-&gt;MyLabel,继承QWidget,实际要继承QLabel,这里没有所以还要到代码中修改。打开mylabel.h，将<code>#include&lt;QWidget&gt;</code>修改为<code>#include &lt;QLabel&gt;</code>,public继承为QLabel，打开mylabel.cpp，修改继承为QLabel。<br>打开widget.ui，在标签上右键-&gt;提升为-&gt;基类QLabel,类名MyLabel，全局包含-&gt;添加-&gt;提升，接下来要做鼠标进入和离开的捕获，打开mylabel.h文件，public下添加以下代码：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//鼠标进入</span></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">enterEvent</span><span class="params">(QEvent *)</span></span>;</span><br><span class="line"><span class="comment">//鼠标离开</span></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">leaveEvent</span><span class="params">(QEvent *)</span></span>;</span><br></pre></td></tr></table></figure>
<p>在mylabel.cpp文件里加入实现：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">MyLabel::enterEvent</span><span class="params">(QEvent *)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">qDebug</span>()&lt;&lt;<span class="string">&quot;鼠标进入&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">MyLabel::leaveEvent</span><span class="params">(QEvent *)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="built_in">qDebug</span>()&lt;&lt;<span class="string">&quot;鼠标离开&quot;</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>Ctrl + Shift + A打开帮助文档输入QLabel,往下翻找到Reimplemented Protected Functions，可以看到有许多可重写的事件，打开mylabel.h，添加代码：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">mouseMoveEvent</span><span class="params">(QMouseEvent *ev)</span></span>;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">mousePressEvent</span><span class="params">(QMouseEvent *ev)</span></span>;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">mouseReleaseEvent</span><span class="params">(QMouseEvent *ev)</span></span>;</span><br></pre></td></tr></table></figure>
<p>添加头文件<code>#include&lt;QMouseEvent&gt;</code>,包含<strong>字符串格式化</strong>，在mylabel.cpp文件里加入上面函数的实现：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//鼠标按下</span></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">MyLabel::mousePressEvent</span><span class="params">(QMouseEvent *ev)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//只有鼠标左键按下才输出</span></span><br><span class="line">    <span class="keyword">if</span>(ev-&gt;<span class="built_in">button</span>()==Qt::LeftButton)</span><br><span class="line">    &#123;</span><br><span class="line">        QString str = <span class="built_in">QString</span>(<span class="string">&quot;鼠标按下 x=%1 y=%2&quot;</span>).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">x</span>()).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">y</span>());</span><br><span class="line">        <span class="built_in">qDebug</span>()&lt;&lt;str;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//鼠标释放</span></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">MyLabel::mouseReleaseEvent</span><span class="params">(QMouseEvent *ev)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//只有鼠标左键按下才输出</span></span><br><span class="line">    <span class="keyword">if</span>(ev-&gt;<span class="built_in">button</span>()==Qt::LeftButton)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//字符串格式化,使用%加给变量数字占位</span></span><br><span class="line">        QString str = <span class="built_in">QString</span>(<span class="string">&quot;鼠标释放 x=%1 y=%2&quot;</span>).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">x</span>()).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">y</span>());</span><br><span class="line">        <span class="built_in">qDebug</span>()&lt;&lt;str;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//鼠标移动</span></span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">MyLabel::mouseMoveEvent</span><span class="params">(QMouseEvent *ev)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//只有鼠标左键按下才输出</span></span><br><span class="line">    <span class="comment">//if(ev-&gt;button()==Qt::LeftButton)//移动过程中左右键可以切换，因此不输出</span></span><br><span class="line">    <span class="keyword">if</span>(ev-&gt;<span class="built_in">buttons</span>() &amp; Qt::LeftButton)<span class="comment">//位与操作，保证只有左键移动才输出</span></span><br><span class="line">    <span class="comment">//在mousePressEvent中找到Public Functions下的button(),点入后再点see also可以看到各种按键的状态码</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//字符串格式化,使用%加给变量数字占位</span></span><br><span class="line">        QString str = <span class="built_in">QString</span>(<span class="string">&quot;鼠标移动 x=%1 y=%2&quot;</span>).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">x</span>()).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">y</span>());</span><br><span class="line">        <span class="built_in">qDebug</span>()&lt;&lt;str;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>接着取消掉左右键的识别，只要鼠标在label上悬停移动，就可以显示移动，通过向构造函数添加代码<code>this-&gt;setMouseTracking(true);</code>并注释掉之前的左键判断就可以实现。</p>
<ul>
<li>1.鼠标进入——enterEvent</li>
<li>2.鼠标离开——leaveEvent</li>
<li>3.鼠标按下——mousePressEvent</li>
<li>4.鼠标释放——mouseReleaseEvent</li>
<li>5.鼠标移动——mouseMoveEvent</li>
<li>6.通过ev可以获取x,y坐标;也可以通过<code>ev-&gt;button()</code>知道按下的是左右中哪个键;如果是判断移动状态，可以通过<code>ev-&gt;buttons() &amp; Qt::LeftButton</code>位与左键实现</li>
<li>7.QString格式化字符串<code>QString(&quot;字符串 x=%1 y=%2&quot;).arg(ev-&gt;x()).arg(ev-&gt;y());</code></li>
<li>8.设置鼠标追踪<code>this-&gt;setMouseTracking(true);</code></li>
</ul>
<h1 id="11-定时器事件"><a href="#11-定时器事件" class="headerlink" title="11.定时器事件"></a>11.定时器事件</h1><ul>
<li>1.第一种定时器使用<br>  还是在QtEvent项目中的widget.ui中拖入一个label,设置边框frame为panel,在widget.h做出定时器声明<code>void timerEvent(QTimerEvent *);</code>，然后在widget.cpp文件里写入定时器的实现：  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">Widget::timerEvent</span><span class="params">(QTimerEvent *)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="type">static</span> <span class="type">int</span> num=<span class="number">1</span>;</span><br><span class="line">    ui-&gt;label_2-&gt;<span class="built_in">setText</span>(QString::<span class="built_in">number</span>(num++));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
  为了使定时器运行，还要在构造函数里加入：<code>startTimer(1000);//定时器间隔为1000毫秒</code>来启动定时器，并且num一定要是<strong>static</strong>类型，只在开始时初始化一次，否则每次启动定时器都初始化为1，一直显示1。<br>  接下来再向widget.ui中拖入一个label,设置边框frame为WinPanel,这个label用来显示每过2秒更改数字，构造函数加入<code>startTimer(2000);//定时器间隔为2秒</code>，timerEvent()函数添加代码：  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">int</span> num2=<span class="number">1</span>;</span><br><span class="line">ui-&gt;label_3-&gt;<span class="built_in">setText</span>(QString::<span class="built_in">number</span>(num2++));</span><br></pre></td></tr></table></figure>
  但是启动了2个定时器，却无法确定哪个定时器调用哪个label,在帮助文档输入QTimerEvent,在Public Functions找到timeId()，这是定时器的唯一标识符，点进去后找到QObject::startTimer()点进去，可以看到startTimer()有返回值，且返回值就是定时器标识timeId()。所以打开widget.h加入两个成员id1,id2用来表示不同的定时器，再在构造函数里接受标识符：  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">id1 = <span class="built_in">startTimer</span>(<span class="number">1000</span>);<span class="comment">//定时器间隔为1000毫秒</span></span><br><span class="line">id2 = <span class="built_in">startTimer</span>(<span class="number">2000</span>);<span class="comment">//定时器间隔为2秒</span></span><br></pre></td></tr></table></figure>
  然后在timerEvent()函数中加入判断：  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">Widget::timerEvent</span><span class="params">(QTimerEvent *e)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(e-&gt;<span class="built_in">timerId</span>()==id1)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">static</span> <span class="type">int</span> num=<span class="number">1</span>;</span><br><span class="line">        ui-&gt;label_2-&gt;<span class="built_in">setText</span>(QString::<span class="built_in">number</span>(num++));</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(e-&gt;<span class="built_in">timerId</span>()==id2)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">static</span> <span class="type">int</span> num2=<span class="number">1</span>;</span><br><span class="line">        ui-&gt;label_3-&gt;<span class="built_in">setText</span>(QString::<span class="built_in">number</span>(num2++));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>2.第二种定时器使用<br>  当一个程序中定时器事件很多时，若按第一种方法，需要定义许多id且要进行多次判断,太过麻烦，因此我们使用第二种方法，引入定时器类<code>#include&lt;QTimer&gt;</code>。<br>  向widget.ui中拖入一个label,设置边框frame为Box,边框阴影frameShadow设置为Sunken，这个label每隔0.5秒就更改数字。在构造函数中增加如下代码：  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">QTimer * timer = <span class="keyword">new</span> <span class="built_in">QTimer</span>(<span class="keyword">this</span>);</span><br><span class="line">timer-&gt;<span class="built_in">start</span>(<span class="number">500</span>);</span><br><span class="line"><span class="built_in">connect</span>(timer, &amp;QTimer::timeout, [=]()&#123;</span><br><span class="line">    <span class="type">static</span> <span class="type">int</span> num=<span class="number">1</span>;</span><br><span class="line">    ui-&gt;label_4-&gt;<span class="built_in">setText</span>(QString::<span class="built_in">number</span>(num++));</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
  我们还可以实现按下按钮，定时器暂停计时的功能。向widget.ui中拖入一个QPushButton，更名为btn_pause，构造函数增加以下代码：  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">connect</span>(ui-&gt;btn_pause, &amp;QPushButton::clicked, [=]()&#123;</span><br><span class="line">    timer-&gt;<span class="built_in">stop</span>();</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="12-事件分发器"><a href="#12-事件分发器" class="headerlink" title="12.事件分发器"></a>12.事件分发器</h1><p><code>bool event(QEvent *)</code>如果用户想在事件分发前捕获事件，不向下分发，可以return true代表自定义处理。<br>在帮助文档中搜索QEvent,在Public Functions中找到<code>QEvent::Type  type() const</code>，点进去再点QEvent::Type即可看到所有种类的事件event。接下来打开mylabel.h,定义<code>bool event(QEvent* e);</code>函数，回到mylabel.cpp对其进行实现：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">bool</span> <span class="title">MyLabel::event</span><span class="params">(QEvent* e)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(e-&gt;<span class="built_in">type</span>() == QEvent::MouseButtonPress)</span><br><span class="line">    &#123;</span><br><span class="line">        QMouseEvent * ev = <span class="built_in">static_cast</span>&lt;QMouseEvent*&gt;(e);</span><br><span class="line">        QString str = <span class="built_in">QString</span>(<span class="string">&quot;event事件中鼠标按下 x=%1 y=%2&quot;</span>).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">x</span>()).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">y</span>());</span><br><span class="line">        <span class="built_in">qDebug</span>()&lt;&lt;str;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;<span class="comment">//代表如果是鼠标按下，用户自己处理</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//其他事件交给父类处理</span></span><br><span class="line">    <span class="keyword">return</span> QLabel::<span class="built_in">event</span>(e);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p><strong>C++类型转换</strong>：转换后的类型 转换后的变量名 &#x3D; static_cast&lt;转换后的类型&gt;(转换前的变量名);</p>
</blockquote>
<h1 id="13-事件过滤器"><a href="#13-事件过滤器" class="headerlink" title="13.事件过滤器"></a>13.事件过滤器</h1><p><strong>在事件分发器拦截之前，还能进行一次拦截，即事件过滤。</strong>使用事件过滤器需要两步：</p>
<ul>
<li>1.给对应控件安装 事件过滤器</li>
<li>2.重写eventFilter事件</li>
</ul>
<p>还是QtEvent项目，在widget.h中添加函数<code>bool eventFilter(QObject * obj, QEvent * e);</code>，obj用于判断控件，可能不止一个控件在安装，在widget.cpp的构造函数安装事件过滤器：<code>ui-&gt;label-&gt;installEventFilter(this);</code>,然后加入头文件<code>#include&lt;QDebug&gt;</code>和<code>#include&lt;QMouseEvent&gt;</code>,还要重写eventFilter()函数：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">bool</span> <span class="title">Widget::eventFilter</span><span class="params">(QObject * obj, QEvent * e)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(obj == ui-&gt;label)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span>(e-&gt;<span class="built_in">type</span>() == QEvent::MouseButtonPress)</span><br><span class="line">        &#123;</span><br><span class="line">            QMouseEvent * ev = <span class="built_in">static_cast</span>&lt;QMouseEvent *&gt;(e);</span><br><span class="line">            QString str = <span class="built_in">QString</span>(<span class="string">&quot;eventFilter事件中鼠标按下 x=%1 y=%2&quot;</span>).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">x</span>()).<span class="built_in">arg</span>(ev-&gt;<span class="built_in">y</span>());</span><br><span class="line">            <span class="built_in">qDebug</span>()&lt;&lt;str;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">true</span>;<span class="comment">//代表如果是鼠标按下，用户自己处理</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//默认处理</span></span><br><span class="line">    <span class="keyword">return</span> QWidget::<span class="built_in">eventFilter</span>(obj, e);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="14-绘图事件"><a href="#14-绘图事件" class="headerlink" title="14.绘图事件"></a>14.绘图事件</h1><h2 id="14-1-基本绘图事件"><a href="#14-1-基本绘图事件" class="headerlink" title="14.1.基本绘图事件"></a>14.1.基本绘图事件</h2><p>新建项目QPainter,在widget.h里声明绘图事件函数：<code>void paintEvent(QPaintEvent *);</code>,<strong>定时器事件和绘图事件系统会自动调用</strong>，再回到widget.cpp里添加头文件<code>#include&lt;QPainter&gt;</code>,并实现paintEvent()函数：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">Widget::paintEvent</span><span class="params">(QPaintEvent *)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">//声明画家对象，在窗口设备中绘制图片</span></span><br><span class="line">    <span class="function">QPainter <span class="title">painter</span><span class="params">(<span class="keyword">this</span>)</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//指定画笔</span></span><br><span class="line">    <span class="function">QPen <span class="title">pen</span><span class="params">(QColor(<span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>))</span></span>;</span><br><span class="line">    <span class="comment">//设置笔宽</span></span><br><span class="line">    pen.<span class="built_in">setWidth</span>(<span class="number">2</span>);</span><br><span class="line">    <span class="comment">//设置风格</span></span><br><span class="line">    pen.<span class="built_in">setStyle</span>(Qt::DotLine);</span><br><span class="line">    <span class="comment">//让画家拿起红色笔</span></span><br><span class="line">    painter.<span class="built_in">setPen</span>(pen);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//画刷给封闭图形填充颜色</span></span><br><span class="line">    <span class="function">QBrush <span class="title">brush</span><span class="params">(Qt::blue)</span></span>;</span><br><span class="line">    <span class="comment">//设置画刷风格</span></span><br><span class="line">    brush.<span class="built_in">setStyle</span>(Qt::CrossPattern);</span><br><span class="line">    <span class="comment">//让画家拿起画刷</span></span><br><span class="line">    painter.<span class="built_in">setBrush</span>(brush);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//画线</span></span><br><span class="line">    painter.<span class="built_in">drawLine</span>(<span class="built_in">QPoint</span>(<span class="number">0</span>,<span class="number">0</span>), <span class="built_in">QPoint</span>(<span class="number">100</span>,<span class="number">100</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//画圆</span></span><br><span class="line">    painter.<span class="built_in">drawEllipse</span>( <span class="built_in">QPoint</span>(<span class="number">100</span>,<span class="number">100</span>), <span class="number">50</span>,<span class="number">50</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//画矩形</span></span><br><span class="line">    painter.<span class="built_in">drawRect</span>(<span class="built_in">QRect</span>(<span class="number">50</span>, <span class="number">50</span>, <span class="number">30</span>, <span class="number">30</span>));</span><br><span class="line"></span><br><span class="line">    <span class="comment">//画文字</span></span><br><span class="line">    painter.<span class="built_in">drawText</span>(<span class="built_in">QRect</span>(<span class="number">0</span>, <span class="number">150</span>, <span class="number">300</span>, <span class="number">100</span>),<span class="string">&quot;多情自古空余恨，此恨绵绵无绝期&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="14-2-高级绘图事件"><a href="#14-2-高级绘图事件" class="headerlink" title="14.2.高级绘图事件"></a>14.2.高级绘图事件</h2><p>注释掉刚才除声明画家对象的代码，画两个圆，并设置抗锯齿：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">painter.<span class="built_in">drawEllipse</span>(<span class="built_in">QPoint</span>(<span class="number">100</span>,<span class="number">100</span>), <span class="number">50</span>, <span class="number">50</span>);</span><br><span class="line"><span class="comment">//设置抗锯齿 效率低</span></span><br><span class="line">painter.<span class="built_in">setRenderHint</span>(QPainter::Antialiasing);</span><br><span class="line">painter.<span class="built_in">drawEllipse</span>(<span class="built_in">QPoint</span>(<span class="number">250</span>,<span class="number">100</span>), <span class="number">50</span>, <span class="number">50</span>);</span><br></pre></td></tr></table></figure>
<p>注释掉刚才的代码，画两个矩形：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">painter.<span class="built_in">drawRect</span>(<span class="built_in">QRect</span>(<span class="number">20</span>, <span class="number">20</span>, <span class="number">50</span>, <span class="number">50</span>));</span><br><span class="line"></span><br><span class="line"><span class="comment">//移动画家</span></span><br><span class="line">painter.<span class="built_in">translate</span>(<span class="number">100</span>, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">painter.<span class="built_in">save</span>();<span class="comment">//保存画家状态</span></span><br><span class="line"></span><br><span class="line">painter.<span class="built_in">drawRect</span>(<span class="built_in">QRect</span>(<span class="number">20</span>, <span class="number">20</span>, <span class="number">50</span>, <span class="number">50</span>));</span><br><span class="line"></span><br><span class="line">painter.<span class="built_in">translate</span>(<span class="number">100</span>, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//还原画家状态,即还原到刚才保存的状态,所以第2,3个矩形会重叠</span></span><br><span class="line">painter.<span class="built_in">restore</span>();</span><br><span class="line"></span><br><span class="line">painter.<span class="built_in">drawRect</span>(<span class="built_in">QRect</span>(<span class="number">20</span>, <span class="number">20</span>, <span class="number">50</span>, <span class="number">50</span>));</span><br></pre></td></tr></table></figure>
<p>注释掉之前的代码，利用画家画出图片，先导入资源文件，在项目名上右键-&gt;Add New-&gt;Qt Resource File-&gt;res-&gt;生成res.qrc文件，将图片文件复制到项目目录下，添加前缀&#x2F;,添加文件，Ctrl + B编译即可看到资源文件。<br>添加代码<code>painter.drawPixmap(10,100, QPixmap(&quot;:/img/save.svg&quot;));</code>运行即可看到图片，我们向widget.ui拖入一个QPushButton按钮，命名为btn_move，实现每按一次图片就向右移动固定距离的功能。向widget.h中添加：<code>int posX;</code>,回到widget.cpp中，在构造函数里添加代码：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">posX = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//点击按钮,图片移动</span></span><br><span class="line"><span class="built_in">connect</span>(ui-&gt;btn_move, &amp;QPushButton::clicked, [=]()&#123;</span><br><span class="line">    <span class="comment">//手动调用paintEvent()函数,update()</span></span><br><span class="line">    <span class="built_in">update</span>();</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>paintEvent()函数内的代码如下;</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//声明画家对象，在窗口设备中绘制图片</span></span><br><span class="line"><span class="function">QPainter <span class="title">painter</span><span class="params">(<span class="keyword">this</span>)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">//图片超出屏幕,再设置回来</span></span><br><span class="line"><span class="keyword">if</span>(posX&gt;<span class="keyword">this</span>-&gt;<span class="built_in">width</span>())</span><br><span class="line">    posX = <span class="number">0</span>;</span><br><span class="line">posX += <span class="number">5</span>;</span><br><span class="line"><span class="comment">//利用画家画图片</span></span><br><span class="line">painter.<span class="built_in">drawPixmap</span>(posX, <span class="number">100</span>, <span class="built_in">QPixmap</span>(<span class="string">&quot;:/img/save.svg&quot;</span>));</span><br></pre></td></tr></table></figure>
<ul>
<li>1.设置抗锯齿<code>setRenderHint(QPainter::抗锯齿状态码);</code></li>
<li>2.保存画家状态<code>save()</code></li>
<li>3.取出画家状态<code>restore()</code></li>
<li>4.利用画家画出资源图片<code>drawPixmap(x, y, QPixmap(&quot;资源路径&quot;));</code></li>
<li>5.图片移动<code>translate(x, y)</code></li>
<li>6.手动调用绘图事件<code>update()</code></li>
</ul>
<h2 id="14-3-绘图设备"><a href="#14-3-绘图设备" class="headerlink" title="14.3.绘图设备"></a>14.3.绘图设备</h2><p>绘图设备是指继承QPainterDevice的子类，Qt一共提供了4个这样的类，分别是QPixmap,QBitmap,QImage,QPicture。其中，</p>
<ul>
<li><p>1.QPixmap专门为图像在屏幕上的演示做优化。<br>widget.cpp构造函数下的示例代码如下：</p>
  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//QPixmap做绘图设备,对不同平台的设备做显示优化</span></span><br><span class="line"><span class="function">QPixmap <span class="title">pix</span><span class="params">(<span class="number">300</span>, <span class="number">300</span>)</span></span>;</span><br><span class="line"><span class="comment">//更改填充色为白色,默认黑色</span></span><br><span class="line">pix.<span class="built_in">fill</span>(Qt::white);</span><br><span class="line"><span class="function">QPainter <span class="title">painter</span><span class="params">(&amp;pix)</span></span>;</span><br><span class="line">painter.<span class="built_in">setPen</span>(<span class="built_in">QPen</span>(Qt::red));</span><br><span class="line">painter.<span class="built_in">drawEllipse</span>(<span class="built_in">QPoint</span>(<span class="number">150</span>, <span class="number">150</span>), <span class="number">100</span> ,<span class="number">100</span>);</span><br><span class="line"><span class="comment">//保存</span></span><br><span class="line">pix.<span class="built_in">save</span>(<span class="string">&quot;D:\\pix.png&quot;</span>);</span><br></pre></td></tr></table></figure></li>
<li><p>2.QBitmap是QPixmap的一个子类，它的色深限定为1（只有黑白两色），可以使用QPixmap的isQBitmap()函数来确定QPixmap是不是一个QBitmap。  </p>
</li>
<li><p>3.QImage专门为图像的像素级访问做了优化，也就是可以更改像素点的颜色。<br>在帮助文档中查询QImage -&gt; Public Functions -&gt; QImage(int width, int height, QImage::Format format) -&gt; QImage::Format -&gt; 常用的QImage::Format_RGB32，带A的是可以调节透明度的。在widget.cpp中注释之前的代码并向构造函数加入新代码：</p>
  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//QImage做绘图设备</span></span><br><span class="line"><span class="function">QImage  <span class="title">img</span><span class="params">(<span class="number">300</span>, <span class="number">300</span>, QImage::Format_RGB32)</span></span>;</span><br><span class="line">img.<span class="built_in">fill</span>(Qt::white);</span><br><span class="line"><span class="function">QPainter <span class="title">painter</span><span class="params">(&amp;img)</span></span>;</span><br><span class="line">painter.<span class="built_in">setPen</span>(<span class="built_in">QPen</span>(Qt::green));</span><br><span class="line">painter.<span class="built_in">drawEllipse</span>(<span class="built_in">QPoint</span>(<span class="number">150</span>, <span class="number">150</span>), <span class="number">100</span> ,<span class="number">100</span>);</span><br><span class="line"><span class="comment">//保存</span></span><br><span class="line">img.<span class="built_in">save</span>(<span class="string">&quot;D:\\img.png&quot;</span>);</span><br></pre></td></tr></table></figure>
<p>  向widget.h添加代码：<code>void paintEvent(QPaintEvent *);</code>,添加图片资源文件，并在widget.cpp里添加该函数的实现：</p>
  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="type">void</span> <span class="title">Widget::paintEvent</span><span class="params">(QPaintEvent * e)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    QImage img;</span><br><span class="line">    img.<span class="built_in">load</span>(<span class="string">&quot;:/img/new.svg&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="function">QPainter <span class="title">painter</span><span class="params">(<span class="keyword">this</span>)</span></span>;</span><br><span class="line">    <span class="comment">//在画出图片前修改像素点</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> i=<span class="number">0</span>; i&lt;<span class="number">20</span>; ++i) &#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="type">int</span> j=<span class="number">0</span>;j&lt;<span class="number">20</span>;++j) &#123;</span><br><span class="line">            QRgb val = <span class="built_in">qRgb</span>(<span class="number">255</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">            img.<span class="built_in">setPixel</span>(i, j, val);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    painter.<span class="built_in">drawImage</span>(<span class="number">0</span>, <span class="number">0</span>, img);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>4.QPicture可以记录和重现QPainter的各条命令。<br>加入头文件<code>#include&lt;QPicture&gt;</code>,在widget.cpp中注释之前的代码并向构造函数加入新代码：</p>
  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">QPicture pic;<span class="comment">//记录和重现QPainter的各条命令</span></span><br><span class="line">QPainter painter;</span><br><span class="line">painter.<span class="built_in">begin</span>(&amp;pic);</span><br><span class="line">painter.<span class="built_in">setPen</span>(<span class="built_in">QPen</span>(Qt::blue));</span><br><span class="line">painter.<span class="built_in">drawEllipse</span>(<span class="built_in">QPoint</span>(<span class="number">150</span>, <span class="number">150</span>), <span class="number">100</span> ,<span class="number">100</span>);</span><br><span class="line">painter.<span class="built_in">end</span>();</span><br><span class="line"></span><br><span class="line">pic.<span class="built_in">save</span>(<span class="string">&quot;D:\\img.png&quot;</span>);</span><br></pre></td></tr></table></figure>
<p>  上面程序的img.png是无法打开的，因为它记录了QPainter的各条命令，需要在paintEvent()函数里重现：</p>
  <figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//重现QPicture的绘图命令</span></span><br><span class="line"><span class="function">QPainter <span class="title">painter</span><span class="params">(<span class="keyword">this</span>)</span></span>;</span><br><span class="line">QPicture pic;</span><br><span class="line">pic.<span class="built_in">load</span>(<span class="string">&quot;D:\\img.png&quot;</span>);</span><br><span class="line"></span><br><span class="line">painter.<span class="built_in">drawPicture</span>(<span class="number">0</span>, <span class="number">0</span>, pic);</span><br></pre></td></tr></table></figure></li>
</ul>
<hr>

        
            <div class="donate-container">
    <div class="donate-button">
        <button id="donate-button">赞赏</button>
    </div>
    <div class="donate-img-container hide" id="donate-img-container">
        <img id="donate-img" src="" data-src="/myblog/img/donate.jpg">
        <p> 感谢鼓励 </p>
    </div>
</div>
        
        <br />
        <div id="comment-container">
        </div>
        <div id="disqus_thread"></div>
        <div id="lv-container"></div>
        <div class="giscus"></div>
    </div>
</div>

    </div>
</div>


<footer class="footer">
    <ul class="list-inline text-center">
        
        

        

        

        
        <li>
            <a target="_blank"  href="https://github.com/samuel-24276">
                            <span class="fa-stack fa-lg">
                                <i class="iconfont icon-github"></i>
                            </span>
            </a>
        </li>
        

        

    </ul>
    
    <p>
        <span>/</span>
        
        <span><a target="_blank" rel="noopener" href="https://github.com/samuel-24276">samuel-24276&#39;s Page</a></span>
        <span>/</span>
        
        <span><a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/">北京-未备案</a></span>
        <span>/</span>
        
        <span><a href="#">返回顶部</a></span>
        <span>/</span>
        
    </p>
    
    <p>
        <span id="busuanzi_container_site_pv">
            <span id="busuanzi_value_site_pv"></span>PV
        </span>
        <span id="busuanzi_container_site_uv">
            <span id="busuanzi_value_site_uv"></span>UV
        </span>
        Created By <a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>  Theme <a target="_blank" rel="noopener" href="https://github.com/aircloud/hexo-theme-aircloud">AirCloud</a></p>
</footer>




</body>

<script>
    // We expose some of the variables needed by the front end
    window.hexo_search_path = "search.json"
    window.hexo_root = "/myblog/"
    window.isPost = true
</script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

<script src="/myblog/js/index.js"></script>

<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>






    <script type="text/javascript">
       (function() {
           if (typeof LivereTower === 'function') { return; }

           var j, d = document.getElementById('lv-container');

           d.setAttribute('data-id','city');
           d.setAttribute('data-uid' , 'MTAyMC80OTA5OC8yNTU5Mw==');

           j = document.createElement('script');
           j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
           j.async = true;

           d.appendChild(j);
       })();
    </script>
    <noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
    </div>

</html>
